package org.example.spring.carsalemanagementsystem.controller;

import lombok.RequiredArgsConstructor;
import org.example.spring.carsalemanagementsystem.entity.Client;
import org.example.spring.carsalemanagementsystem.service.ClientService;
import org.example.spring.carsalemanagementsystem.utils.Page;
import org.example.spring.carsalemanagementsystem.utils.Result;
import org.example.spring.carsalemanagementsystem.vo.ClientFuzzyVo;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/client")
@RequiredArgsConstructor
public class ClientController {
    private final ClientService clientService;
    @GetMapping("/findPages")
    public Result findPages(@RequestParam(required = false)Long pageNum,
                            @RequestParam(required = false)Long pageSize){
        Page<Client> pages = clientService.findPages(pageNum, pageSize);
        return Result.success().put(pages);
    }
    @GetMapping("/findList")
    public Result findList(){
        List<Client> list = clientService.findList();
        return Result.success().put(list);
    }
    @PostMapping("/insert")
    public Result insert(@RequestBody Client client){
        clientService.insertOne(client);
        return Result.success();
    }
    @PostMapping("/delete")
    public Result delete(String clientid){
        clientService.deleteById(clientid);
        return Result.success();
    }
    @PostMapping("/update")
    public Result update(@RequestBody Client client){
        clientService.updateById(client);
        return Result.success();
    }
    @PostMapping("/change")
    public Result change(String clientid){
        clientService.changeStatus(clientid);
        return Result.success();
    }
    @PostMapping("/fuzzy")
    public Result fuzzy(@RequestBody ClientFuzzyVo vo){
        Page<Client> pages = clientService.findPagesByKey(vo);
        return Result.success().put(pages);
    }
}
